package com.ruoyi.messages.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.messages.domain.SysPublishStatusDTO;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.messages.domain.SysEvent;
import com.ruoyi.messages.service.ISysEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动管理Controller
 *
 * @author ruoyi
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/messages/eventManage")
public class SysEventController extends BaseController
{
    @Autowired
    private ISysEventService sysEventService;


    /**
     * 查询活动管理列表
     */
    @PreAuthorize("@ss.hasPermi('messages:eventManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysEvent sysEvent)
    {

        sysEvent.setDeptId(SecurityUtils.getDeptId());

        startPage();
        List<SysEvent> list = sysEventService.selectSysEventList(sysEvent);


        return getDataTable(list);
    }

    /**
     * 导出活动管理列表
     */
    @PreAuthorize("@ss.hasPermi('messages:eventManage:export')")
    @Log(title = "活动管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysEvent sysEvent)
    {
        List<SysEvent> list = sysEventService.selectSysEventList(sysEvent);
        ExcelUtil<SysEvent> util = new ExcelUtil<SysEvent>(SysEvent.class);
        util.exportExcel(response, list, "活动管理数据");
    }

    /**
     * 获取活动管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('messages:eventManage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysEventService.selectSysEventById(id));
    }

    /**
     * 新增活动管理
     */
    @PreAuthorize("@ss.hasPermi('messages:eventManage:add')")
    @Log(title = "活动管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysEvent sysEvent)
    {
        return toAjax(sysEventService.insertSysEvent(sysEvent));
    }

    /**
     * 修改活动管理
     */
    @PreAuthorize("@ss.hasPermi('messages:eventManage:edit')")
    @Log(title = "活动管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysEvent sysEvent)
    {
        return toAjax(sysEventService.updateSysEvent(sysEvent));
    }

    /**
     * 删除活动管理
     */
    @PreAuthorize("@ss.hasPermi('messages:eventManage:remove')")
    @Log(title = "活动管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysEventService.deleteSysEventByIds(ids));
    }


    @PostMapping("/resetStatus")
    public AjaxResult resetStatus(@RequestBody SysPublishStatusDTO statusDTO)
    {
        return toAjax(sysEventService.updateStatus(statusDTO));
    }
}
